#include "MusicUI.h"
#include "lvgl/lvgl.h"
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <string.h>
#include "sys.h"

#define BOTTOM_CONT_HEIGHT 80
#define MUSIC_LIST_WIDTH 330

LV_IMG_DECLARE(butterfly)
LV_IMG_DECLARE(mode_all_circle)
LV_IMG_DECLARE(next)
LV_IMG_DECLARE(prev)
LV_IMG_DECLARE(mode_one_circle)
LV_IMG_DECLARE(pause_icon)
LV_IMG_DECLARE(playing)
LV_IMG_DECLARE(mode_random)
LV_IMG_DECLARE(volume)


static lv_ft_info_t font20;
static lv_ft_info_t font24;
static lv_ft_info_t font28;
static lv_ft_info_t font34;


typedef struct
{
  lv_obj_t *cont;        // 容器
  lv_obj_t *progSlider; // 音乐进度滑动条
  lv_obj_t *prev;        // 上一曲
  lv_obj_t *pause;       // 暂停
  lv_obj_t *next;        // 下一曲
  lv_obj_t *mode;        // 模式-单曲，随机，顺序
  lv_obj_t *volume;      // 用于弹出音量调节slider
  lv_obj_t *timeLabel;  // 播放时间label
  lv_obj_t *musicLabel; // 歌曲名称label
} MusicBottomObj;

static void drag_event_handler(lv_event_t *e);
static void music_bottom_prev_btn_click_event_cb(lv_event_t *e);
static void music_bottom_next_btn_click_event_cb(lv_event_t *e);
static void music_bottom_pause_btn_click_event_cb(lv_event_t *e);
static void music_bottom_mode_btn_click_event_cb(lv_event_t *e);
static void music_bottom_volume_btn_click_event_cb(lv_event_t *e);
static void music_list_btn_event_cb(lv_event_t *e);
static void music_progress_slider_event_cb(lv_event_t *e);
static void music_volume_slider_event_cb(lv_event_t *e);

// LCD分辨率
static lv_coord_t lcdW = 480;
static lv_coord_t lcdH = 272;

// 界面回调函数集合
static MusicUI::Operations uiOpts;

// 背景图片
static lv_obj_t *backImage;

// 退出按钮
static lv_obj_t *exitBtn;

// 音乐列表
static lv_obj_t *musicList;

// 底部元素集合
static MusicBottomObj musicBottomObj;

// 歌词滚轮
static lv_obj_t *lyricRoller;

// 保存当前播放的音乐列表btn
static lv_obj_t *playingMusicBtn = nullptr;

//音量调节slider
static lv_obj_t *volumeSlider = nullptr;

//音乐进度slider是否被按下
static bool musicSliderPressed = false;


/**
  *@brief 初始化界面UI
  *@param opts UI回调函数集合
  */
void MusicUI::create(MusicUI::Operations &opts)
{
  uiOpts = opts;

  // 初始化字体
  font20.name = SystemFontFile;
  font20.weight = 20;
  font20.style = FT_FONT_STYLE_NORMAL;
  font20.mem = nullptr;
  lv_ft_font_init(&font20);

  font24.name = SystemFontFile;
  font24.weight = 24;
  font24.style = FT_FONT_STYLE_NORMAL;
  font24.mem = nullptr;
  lv_ft_font_init(&font24);

  font28.name = SystemFontFile;
  font28.weight = 28;
  font28.style = FT_FONT_STYLE_NORMAL;
  font28.mem = nullptr;
  lv_ft_font_init(&font28);

  font34.name = SystemFontFile;
  font34.weight = 34;
  font34.style = FT_FONT_STYLE_NORMAL;
  font34.mem = nullptr;
  lv_ft_font_init(&font34);

  lcdW = lv_disp_get_hor_res(nullptr);
  lcdH = lv_disp_get_ver_res(nullptr);

  backImage = lv_img_create(lv_scr_act());
  lv_obj_set_size(backImage, lcdW, lcdH);
  lv_obj_center(backImage);
  lv_obj_clear_flag(backImage, LV_OBJ_FLAG_SCROLLABLE); // 禁止滚动
  lv_img_set_src(backImage, "S:./res/background/musicbg.bin");

  // 创建底部元素
  musicBottomObj.cont = lv_obj_create(backImage);
  lv_obj_set_size(musicBottomObj.cont, lcdW, BOTTOM_CONT_HEIGHT);
  lv_obj_align(musicBottomObj.cont, LV_ALIGN_BOTTOM_MID, 0, 0);
  lv_obj_clear_flag(musicBottomObj.cont, LV_OBJ_FLAG_SCROLLABLE); // 禁止滚动
  lv_obj_set_style_radius(musicBottomObj.cont, 0, LV_STATE_DEFAULT);
  lv_obj_set_style_border_width(musicBottomObj.cont, 0, LV_STATE_DEFAULT);                  // 无边框
  lv_obj_set_style_bg_color(musicBottomObj.cont, lv_color_hex(0x000000), LV_STATE_DEFAULT); // 背景黑色
  lv_obj_set_style_bg_opa(musicBottomObj.cont, LV_OPA_50, LV_STATE_DEFAULT);                // 背景透明度

  do
  {
    const lv_img_dsc_t *icon[] = {&prev, &pause_icon, &next, &mode_all_circle, &volume};
    lv_obj_t **imgs[] = {&musicBottomObj.prev, &musicBottomObj.pause, &musicBottomObj.next, &musicBottomObj.mode, &musicBottomObj.volume};
    lv_event_cb_t imgCbs[] =
        {
            music_bottom_prev_btn_click_event_cb,
            music_bottom_pause_btn_click_event_cb,
            music_bottom_next_btn_click_event_cb,
            music_bottom_mode_btn_click_event_cb,
            music_bottom_volume_btn_click_event_cb};

    for (int i = 0; i < 5; i++) // 创建5img按钮
    {
      imgs[i][0] = lv_img_create(musicBottomObj.cont); // img按钮
      lv_img_set_src(imgs[i][0], icon[i]);
      lv_obj_set_style_img_opa(imgs[i][0], LV_OPA_60, LV_STATE_DEFAULT);    // 松开时透明度
      lv_obj_set_style_img_opa(imgs[i][0], LV_OPA_COVER, LV_STATE_PRESSED); // 按下时透明度
      lv_obj_add_flag(imgs[i][0], LV_OBJ_FLAG_CLICKABLE);
      lv_obj_add_event_cb(imgs[i][0], imgCbs[i], LV_EVENT_SHORT_CLICKED, nullptr);

      if (i != 0)
        lv_obj_align_to(imgs[i][0], imgs[i - 1][0], LV_ALIGN_OUT_RIGHT_MID, 10, 0);
      else
        lv_obj_align(imgs[i][0], LV_ALIGN_LEFT_MID, 0, 0);
    }
  } while (0);

  // 创建音乐进度滑块条
  musicBottomObj.progSlider = lv_slider_create(musicBottomObj.cont);
  lv_obj_set_size(musicBottomObj.progSlider, 500, 10);
  lv_obj_set_style_bg_color(musicBottomObj.progSlider, lv_color_hex(0xe6e6e6), LV_STATE_DEFAULT);
  lv_obj_set_style_bg_opa(musicBottomObj.progSlider, LV_OPA_60, LV_STATE_DEFAULT);
  lv_obj_set_style_bg_color(musicBottomObj.progSlider, lv_color_hex(0x60bf25), LV_PART_INDICATOR | LV_STATE_DEFAULT);
  lv_obj_set_style_bg_color(musicBottomObj.progSlider, lv_color_hex(0x60bf25), LV_PART_KNOB | LV_STATE_DEFAULT);
  lv_obj_align_to(musicBottomObj.progSlider, musicBottomObj.next, LV_ALIGN_OUT_RIGHT_MID, 15, 0);
  lv_obj_add_event_cb(musicBottomObj.progSlider, music_progress_slider_event_cb, LV_EVENT_RELEASED, nullptr);
  lv_obj_add_event_cb(musicBottomObj.progSlider, music_progress_slider_event_cb, LV_EVENT_PRESSED, nullptr);

  lv_obj_t *music_name_label = lv_label_create(musicBottomObj.cont);
  lv_obj_set_style_text_font(music_name_label, font24.font, LV_STATE_DEFAULT);
  lv_obj_set_style_text_color(music_name_label, lv_color_hex(0xe6e6e6), LV_STATE_DEFAULT);
  lv_label_set_text(music_name_label, "当前无歌曲播放");
  lv_obj_align_to(music_name_label, musicBottomObj.progSlider, LV_ALIGN_OUT_TOP_LEFT, 0, -5);
  musicBottomObj.musicLabel = music_name_label;

  lv_obj_t *timeLabel = lv_label_create(musicBottomObj.cont);
  lv_obj_set_style_text_font(timeLabel, font20.font, LV_STATE_DEFAULT);
  lv_obj_set_style_text_color(timeLabel, lv_color_hex(0xe6e6e6), LV_STATE_DEFAULT);
  lv_label_set_text(timeLabel, "00:00/00:00");
  lv_obj_set_user_data(musicBottomObj.progSlider, timeLabel);
  lv_obj_align_to(timeLabel, musicBottomObj.progSlider, LV_ALIGN_OUT_RIGHT_MID, 15, 0);
  musicBottomObj.timeLabel = timeLabel;

  lv_obj_align_to(musicBottomObj.mode, timeLabel, LV_ALIGN_OUT_RIGHT_MID, 10, 0);
  lv_obj_align_to(musicBottomObj.volume, musicBottomObj.mode, LV_ALIGN_OUT_RIGHT_MID, 10, 0);

  // 创建音乐列表
  musicList = lv_list_create(backImage);
  lv_obj_set_size(musicList, MUSIC_LIST_WIDTH, lcdH - BOTTOM_CONT_HEIGHT);
  lv_obj_align(musicList, LV_ALIGN_TOP_LEFT, 0, 0);
  lv_obj_set_style_bg_opa(musicList, LV_OPA_30, LV_STATE_DEFAULT);          // 设置背景透明度
  lv_obj_set_style_bg_color(musicList, lv_color_black(), LV_STATE_DEFAULT); // 背景黑色
  lv_obj_set_style_border_opa(musicList, LV_OPA_TRANSP, LV_STATE_DEFAULT);  // 设置边框透明
  lv_obj_set_style_radius(musicList, 0, LV_STATE_DEFAULT);                  // 边框圆角为0

  //创建歌词滚筒
  lyricRoller = lv_roller_create(backImage);
  lv_obj_set_size(lyricRoller, lcdW - MUSIC_LIST_WIDTH, 250 );
  lv_obj_align(lyricRoller, LV_ALIGN_RIGHT_MID, 0, 0);     //设置对齐
  lv_obj_clear_flag(lyricRoller, LV_OBJ_FLAG_SCROLLABLE | LV_OBJ_FLAG_CLICKABLE);      //不可滚动不可点击
  lv_obj_set_style_bg_opa(lyricRoller, LV_OPA_TRANSP, LV_STATE_DEFAULT);   //背景透明
  lv_obj_set_style_border_opa(lyricRoller, LV_OPA_TRANSP, LV_STATE_DEFAULT);   //边框透明
  lv_obj_set_style_bg_opa(lyricRoller, LV_OPA_TRANSP, LV_PART_SELECTED | LV_STATE_DEFAULT);   //选中项背景透明
  lv_obj_set_style_text_font(lyricRoller, font28.font, LV_STATE_DEFAULT);     //非选中项字体
  lv_obj_set_style_text_font(lyricRoller, font34.font, LV_PART_SELECTED | LV_STATE_DEFAULT);     //选中项字体
  lv_obj_set_style_text_color(lyricRoller, lv_color_hex(0xffffff), LV_STATE_DEFAULT);
  lv_obj_set_style_text_color(lyricRoller, lv_color_hex(0xe9de9e), LV_PART_SELECTED | LV_STATE_DEFAULT);   //字体颜色
  lv_roller_set_options(lyricRoller, "开启音乐之旅吧~", LV_ROLLER_MODE_NORMAL);
  lv_roller_set_visible_row_count(lyricRoller, LYRIC_SHOW_LINES);     //可见行数5行

  //创建音量slider
  volumeSlider = lv_slider_create(backImage);
  lv_obj_set_size(volumeSlider, 10, 150);

  lv_coord_t x = lcdW - 40;
  lv_coord_t y = lcdH - BOTTOM_CONT_HEIGHT - 150 - 10;
  lv_obj_set_pos(volumeSlider, x, y);

  int cur = 50;
  int max = 100;
  if(uiOpts.getVolumeCb != nullptr)     //获取当前音量和最大值
    uiOpts.getVolumeCb(&cur, &max);

  lv_slider_set_range(volumeSlider, 0, max);
  lv_slider_set_value(volumeSlider, cur, LV_ANIM_OFF);
  lv_obj_add_event_cb(volumeSlider, music_volume_slider_event_cb, LV_EVENT_RELEASED, nullptr);
  lv_obj_set_style_bg_color(volumeSlider, lv_color_hex(0xe6e6e6), LV_STATE_DEFAULT);
  lv_obj_set_style_bg_opa(volumeSlider, LV_OPA_60, LV_STATE_DEFAULT);
  lv_obj_set_style_bg_color(volumeSlider, lv_color_hex(0x60bf25), LV_PART_INDICATOR | LV_STATE_DEFAULT);
  lv_obj_set_style_bg_color(volumeSlider, lv_color_hex(0x60bf25), LV_PART_KNOB | LV_STATE_DEFAULT);
  lv_obj_add_flag(volumeSlider, LV_OBJ_FLAG_HIDDEN);     //隐藏对象

  // 创建退出按钮
  exitBtn = lv_obj_create(backImage);
  lv_obj_set_size(exitBtn, 70, 70);
  lv_obj_set_pos(exitBtn, 935, 200);
  lv_obj_clear_flag(exitBtn, LV_OBJ_FLAG_SCROLLABLE); // 禁止滚动
  lv_obj_set_style_radius(exitBtn, 35, LV_STATE_DEFAULT);
  lv_obj_set_style_bg_color(exitBtn, lv_color_hex(0xffffff), LV_STATE_DEFAULT);
  lv_obj_set_style_border_opa(exitBtn, LV_OPA_TRANSP, LV_STATE_DEFAULT); // A边框透明
  lv_obj_set_style_bg_opa(exitBtn, LV_OPA_50, LV_STATE_DEFAULT);
  lv_obj_set_style_bg_opa(exitBtn, LV_OPA_90, LV_STATE_PRESSED);

  lv_obj_t *img = lv_img_create(exitBtn);
  lv_img_set_src(img, &butterfly);
  lv_obj_align(img, LV_ALIGN_CENTER, 0, 0);
  lv_obj_add_flag(img, LV_OBJ_FLAG_EVENT_BUBBLE);

  lv_obj_add_event_cb(exitBtn, drag_event_handler, LV_EVENT_PRESSING, nullptr);
  if (uiOpts.exitCb != nullptr)
    lv_obj_add_event_cb(
        exitBtn,
        [](lv_event_t *e)
        {
          uiOpts.exitCb();
        },
        LV_EVENT_SHORT_CLICKED, nullptr);
}

/**
 *@brief 释放界面UI
 */
void MusicUI::release(void)
{
  lv_obj_t *btn = nullptr;

  while ((btn = lv_obj_get_child(musicList, -1)) != nullptr)
  {
    char *music_name = (char *)lv_obj_get_user_data(btn);
    if (music_name != nullptr)
      delete[] music_name;

    lv_obj_del(btn);
  }

  lv_obj_del(backImage);

  lv_ft_font_destroy(font20.font);
  lv_ft_font_destroy(font24.font);
  lv_ft_font_destroy(font28.font);
  lv_ft_font_destroy(font34.font);
}

/**
 *@brief 添加一个音乐到列表
 *@param name 音乐文件名称
 */
void MusicUI::addMusicList(const char *name)
{
  // 添加一个按钮到list
  lv_obj_t *btn = lv_list_add_btn(musicList, nullptr, name);
  lv_obj_set_style_bg_opa(btn, LV_OPA_TRANSP, LV_STATE_DEFAULT); // 设置背景透明
  lv_obj_set_style_bg_opa(btn, LV_OPA_30, LV_STATE_PRESSED);     // 设置背景透明度(按下时)
  lv_obj_set_style_text_color(btn, lv_color_hex(0xffffff), LV_STATE_DEFAULT);
  lv_obj_set_style_text_font(btn, font28.font, LV_STATE_DEFAULT); // 设置字体
  lv_obj_add_event_cb(btn, music_list_btn_event_cb, LV_EVENT_SHORT_CLICKED, nullptr);
  lv_obj_t *label = lv_obj_get_child(btn, -1);
  if(label != nullptr)
    lv_label_set_long_mode(label, LV_LABEL_LONG_DOT);

  if (playingMusicBtn == nullptr)
    playingMusicBtn = btn; // 保存地一首歌

  int len = strlen(name) + 1;
  char *musicName = new char[len];
  strcpy(musicName, name);

  lv_obj_set_user_data(btn, musicName);
}

/**
 *@brief 设置音乐播放进度显示
 */
void MusicUI::setPlayProgress(int cur, int total)
{
  lv_slider_set_range(musicBottomObj.progSlider, 0, total);
  if(musicSliderPressed != true)       //未按下时设置
    lv_slider_set_value(musicBottomObj.progSlider, cur, LV_ANIM_OFF);

  lv_label_set_text_fmt(musicBottomObj.timeLabel, "%d:%d/%d:%d", cur / 60, cur % 60, total / 60, total % 60);
}

/***
 *@brief 加载歌词到UI
 *@param lyric 使用\n隔开的所有歌词
 */
void MusicUI::loadLyric(const char *lyric)
{
  if(lyric != nullptr)
    lv_roller_set_options(lyricRoller, lyric, LV_ROLLER_MODE_NORMAL);
  else
    lv_roller_set_options(lyricRoller, "没有找到歌词文件", LV_ROLLER_MODE_NORMAL);
}

/***
 *@brief 设置当前歌词
 *@param id 歌词id
 */
void MusicUI::setLyricId(int id, bool anim)
{
  if(id < 0)
    return;

  lv_anim_enable_t _anim = id && anim ? LV_ANIM_ON : LV_ANIM_OFF;
  lv_roller_set_selected(lyricRoller, id, _anim);
}

/***
 *@brief 根据索引获取对应的音乐文件名
 *@param index 索引
 */
const char *MusicUI::getMusicName(int index)
{
  const char *name = nullptr;

  lv_obj_t *btn = lv_obj_get_child(musicList, index);
  if(btn != nullptr)
  {
    playingMusicBtn = btn;
    name = (const char *)lv_obj_get_user_data(btn);
  }

  return name;
}

/**
 *@brief 在底部显示音乐名称
 *@param name 音乐名
 */
void MusicUI::showMusicName(const char *name)
{
  if(name != nullptr)
    lv_label_set_text(musicBottomObj.musicLabel, name);
}

/**
 *@brief 长按拖动控件事件函数
 */
static void drag_event_handler(lv_event_t *e)
{
  lv_obj_t *obj = lv_event_get_target(e);

  lv_indev_t *indev = lv_indev_get_act();
  if (indev == nullptr)
    return;

  lv_point_t vect;
  lv_indev_get_vect(indev, &vect);

  lv_coord_t x = lv_obj_get_x(obj) + vect.x;
  lv_coord_t y = lv_obj_get_y(obj) + vect.y;
  lv_obj_set_pos(obj, x, y);
}

/**
 *@brief 底部上一曲按钮控件事件函数
 */
static void music_bottom_prev_btn_click_event_cb(lv_event_t *e)
{
  lv_obj_t *btn = lv_event_get_target(e);

  if (playingMusicBtn != nullptr)
  {
    int index = lv_obj_get_index(playingMusicBtn); // 获取当前music btn索引
    index--;                                         // index若为-1,则表示最后一个btn，不需要对负数处理

    lv_obj_t *prev_btn = lv_obj_get_child(musicList, index); // 获取上一个music list btn
    if (prev_btn != nullptr)
    {
      playingMusicBtn = prev_btn;
      const char *musicName = (const char *)lv_obj_get_user_data(prev_btn);
      if (uiOpts.playCb != nullptr && musicName != nullptr)
        uiOpts.playCb(musicName, index);

      lv_img_set_src(musicBottomObj.pause, &playing);
    }
  }
}

/**
 *@brief 底部下一曲按钮控件事件函数
 */
static void music_bottom_next_btn_click_event_cb(lv_event_t *e)
{
  lv_obj_t *btn = lv_event_get_target(e);

  if (playingMusicBtn != nullptr)
  {
    int index = lv_obj_get_index(playingMusicBtn); // 获取当前music btn索引
    int total = lv_obj_get_child_cnt(musicList) - 1;
    index = index < total ? index + 1 : 0; // 设置下一个btn索引

    lv_obj_t *nextBtn = lv_obj_get_child(musicList, index); // 获取下一个music list btn
    if (nextBtn != nullptr)
    {
      playingMusicBtn = nextBtn;
      const char *musicName = (const char *)lv_obj_get_user_data(nextBtn);
      if (uiOpts.playCb != nullptr && musicName != nullptr)
        uiOpts.playCb(musicName, index);

      lv_img_set_src(musicBottomObj.pause, &playing);
    }
  }
}

/**
 *@brief 底部暂停按钮控件事件函数
 */
static void music_bottom_pause_btn_click_event_cb(lv_event_t *e)
{
  lv_obj_t *btn = lv_event_get_target(e);

  int musicState = false;

  if (uiOpts.getStateCb != nullptr)
    musicState = uiOpts.getStateCb();

  if (musicState < 0) // 还没有歌曲播放
  {
    if (playingMusicBtn != nullptr)
    {
      const char *music_name = (const char *)lv_obj_get_user_data(playingMusicBtn);
      if (uiOpts.playCb != nullptr && music_name != nullptr)
        uiOpts.playCb(music_name, 0);
    }
  }
  else
  {
    musicState = !musicState;

    if (musicState == true)
    {
      int index = lv_obj_get_index(playingMusicBtn);

      if (uiOpts.playCb != nullptr)
        uiOpts.playCb(nullptr, index);
    }
    else
    {
      if (uiOpts.pauseCb != nullptr)
        uiOpts.pauseCb();
    }
  }

  lv_img_set_src(musicBottomObj.pause, musicState ? &playing : &pause_icon);
}

/**
 *@brief 底部模式按钮控件事件函数
 */
static void music_bottom_mode_btn_click_event_cb(lv_event_t *e)
{
  lv_obj_t *btn = lv_event_get_target(e);
  const lv_img_dsc_t *mode_src[] = {&mode_all_circle, &mode_one_circle, &mode_random};

  MusicUI::PlayMode mode = MusicUI::PlayMode_ListLoop;

  if(uiOpts.getModeCb != nullptr)
    mode = uiOpts.getModeCb();

  mode = mode < MusicUI::PlayMode_Random ? (MusicUI::PlayMode)(mode + 1) : MusicUI::PlayMode_ListLoop;

  if(uiOpts.setModeCb != nullptr)
    uiOpts.setModeCb(mode);

  lv_img_set_src(btn, mode_src[(int)mode]);
}

/**
 *@brief 底部音量按钮控件事件函数
 */
static void music_bottom_volume_btn_click_event_cb(lv_event_t *e)
{
  lv_obj_t *btn = lv_event_get_target(e);

  lv_obj_flag_t flag = volumeSlider->flags & LV_OBJ_FLAG_HIDDEN;

  if(flag != 0)
    lv_obj_clear_flag(volumeSlider, LV_OBJ_FLAG_HIDDEN);
  else
    lv_obj_add_flag(volumeSlider, LV_OBJ_FLAG_HIDDEN);
}

/**
 *@brief 音乐列表按钮点击事件回调函数
 */
static void music_list_btn_event_cb(lv_event_t *e)
{
  lv_obj_t *btn = lv_event_get_target(e);

  const char *musicName = (const char *)lv_obj_get_user_data(btn);

  playingMusicBtn = btn;
  int index = lv_obj_get_index(playingMusicBtn);

  if (uiOpts.playCb != nullptr)
    uiOpts.playCb(musicName, index);

  lv_img_set_src(musicBottomObj.pause, &playing);
}

/**
 *@brief 音乐进度滑块条滑动事件函数
 */
static void music_progress_slider_event_cb(lv_event_t *e)
{
  lv_obj_t *slider = lv_event_get_target(e);
  lv_event_code_t eventCode = lv_event_get_code(e);

  if(eventCode == LV_EVENT_RELEASED)
  {
    musicSliderPressed = false;
    int cur = lv_slider_get_value(slider);

    if (uiOpts.setCurCb != nullptr)
      uiOpts.setCurCb(cur);
  }
  else if(eventCode == LV_EVENT_PRESSED)
  {
    musicSliderPressed = true;
  }
}

/***
 *@brief 音乐音量滑块条滑动事件函数
 */
static void music_volume_slider_event_cb(lv_event_t *e)
{
  lv_obj_t *slider = lv_event_get_target(e);
  int value = lv_slider_get_value(slider);

  if(uiOpts.setVolumeCb != nullptr)
    uiOpts.setVolumeCb(value);     //设置音量
}

